# -*- coding = utf-8 -*-
#@Time: 2020/10/23 11:56
#@Author: 卜白
#@File: models.py
#@Software: PyCharm

from datetime import datetime
from exts import db

# 用户表
class User(db.Model):
    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    username = db.Column(db.String(15),nullable=False)
    password = db.Column(db.String(100),nullable=False)
    phone = db.Column(db.String(11),unique=True)
    email = db.Column(db.String(30))
    icon = db.Column(db.String(100))
    isdelete = db.Column(db.Boolean,default=False)
    rdatetime = db.Column(db.DateTime,default=datetime.now)

    def __str__(self):
        return self.username

# 照片
class Photo(db.Model):
    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    photo_name = db.Column(db.String(100),nullable=False)
    upload_datetime = db.Column(db.DateTime,default=datetime.now)
    user_id = db.Column(db.Integer,db.ForeignKey('user.id'),nullable=False)     # 与user用户表的id主外键关联
    # # 建立联系
    # user = db.relationship('User', backref='photo')

    def __str__(self):
        return self.photo_name